package ycl.common.base.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import ycl.common.base.entity.BaseEntity;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 数据库层
 *
 * @author: YCL
 * @date: 2021-06-05 00:01:29
 */
@Repository
@Mapper
public interface BaseDao<T extends BaseEntity> extends BaseMapper<T> {

	List<T> findPage(@Param("page") Page<T> page, @Param("query") T query);

	@Select("select id from ${tableName}")
	List<Long> selectIds(String tableName);

	/**
	 * 根据id和用户id查询数据
	 *
	 * @param id
	 * @param userId
	 * @param tableName
	 * @return
	 */
	@Select("select * from ${tableName} where id = #{id} and user_id = #{userId}")
	T selectByIdUserId(@Param("id") Long id, @Param("userId") Long userId, @Param("tableName") String tableName);


	///**
	// * 查询数据库中所有表名
	// *
	// * @param sqlName 数据库名
	// * @return 表名集合
	// */
	//@Select("select table_name from information_schema.tables where table_schema = '${sqlName}'")
	//List<String> selectAllTableName(String sqlName);
	//
	//
	///**
	// * 清空表
	// *
	// * @param tableName 表名
	// */
	//@Select("truncate table ${tableName}")
	//void truncate(String tableName);
}
